package com.sebiotec.manager.adapt;

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sebiotec.manager.R;
import com.sebiotec.manager.model.SearchEntrty;
import com.sebiotec.manager.ui.activity.BookDetailActivity;
import com.jakewharton.rxbinding2.view.RxView;


import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.functions.Consumer;

public class RejectedAdapt extends BaseQuickAdapter<SearchEntrty.RowsBean, BaseViewHolder> {

    public RejectedAdapt(int layoutResId, @Nullable List<SearchEntrty.RowsBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchEntrty.RowsBean item) {
        helper.setText(R.id.tv_upcoming_name, item.getName());
        helper.setText(R.id.tv_num, item.getPassengers() + "");
        RxView.clicks( helper.itemView.findViewById(R.id.card))
                .throttleFirst(2, TimeUnit.SECONDS)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object o) throws Exception {

                            Intent intent =new Intent(getContext(), BookDetailActivity.class);
                            intent.putExtra("BookingId",item.getBookingId());
                            getContext().startActivity(intent);

                    }
                });
        if (item.getBookmark()==0){
            helper.itemView.findViewById(R.id.iv_mark).setVisibility(View.GONE);
        }else{
            helper.itemView.findViewById(R.id.iv_mark).setVisibility(View.VISIBLE);
        }

        if ("".equals(item.getServesUser())){

            helper.itemView.findViewById(R.id.ll_dx).setVisibility(View.GONE);
        }else{
            helper.itemView.findViewById(R.id.ll_dx).setVisibility(View.VISIBLE);

        }
        switch (item.getStatus()) {
            //1:Ambassador pickup 2:Driver pickup 3: Completed(Driver pickdown) 4:Rejected
            case 1:
                helper.setText(R.id.tv_titles,getContext().getString(R.string.adapt_confirmed_bys));

                break;
            case 2:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.greeted_bys));
                break;
            case 3:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.Picked_up_bys));
                break;
            case 4:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.droped_off_bys));
                break;
            case 5:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.completed_bys));
                break;
            case -2:
                helper.setText(R.id.tv_titles,getContext().getString(R.string.cancells));

                break;
            case 9:
                helper.setText(R.id.tv_titles,getContext().getString(R.string.no_show));

                break;
            case 7:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.dispatched_bys));
                break;

            case 0:
                helper.setText(R.id.tv_titles, getContext().getString(R.string.created_bys));
                break;
            case -1:
                helper.setText(R.id.tv_titles,getContext().getString(R.string.is_rejected));
                break;
            default:
                helper.itemView.findViewById(R.id.ll_dx).setVisibility(View.GONE);
                break;
        }
        helper.setText(R.id.tv_address, item.getPickupFrom());
        helper.setText(R.id.tv_pickup_time,item.getPickupDateTime());
        helper.setText(R.id.tv_to_address, item.getDestination());
        helper.setText(R.id.tv_recevied_by,item.getServesDateTime());
        TextView viewById = helper.itemView.findViewById(R.id.tv_upcoming_name);
        TextView viewById1 = helper.itemView.findViewById(R.id.tv_titles);
        TextView viewById2 = helper.itemView.findViewById(R.id.tv_recevied_by);
        viewById.setTextColor(getContext().getColor(R.color.red));
        viewById1.setTextColor(getContext().getColor(R.color.red));
        viewById2.setTextColor(getContext().getColor(R.color.red));



    }
}